// find.js
var app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {

        controls: true,
        dots: true,
        poster: "",
        page: 0,


    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this
        var session_key = wx.getStorageSync('session_key');

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        var that = this
        var session_key = wx.getStorageSync('session_key');
        //轮播图
        wx.request({
                url: app.data.baseUrl + '/api/Discover/bannel',
                data: {
                    session_key: session_key
                },
                success: function(res) {
                    // console.log(res)
                    that.setData({
                        lbt: res.data.data
                    })
                }
            })
            //点赞排行
        wx.request({
            url: app.data.baseUrl + '/api/Discover/mindCount',
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            data: {
                session_key: session_key,
                gengduo: 'more'
            },
            success: function(res) {
                console.log('finds', res)
                var data = res.data.data;
                var paihang = []
                for (var i = 0; i < 6; i++) {
                    paihang[i] = data[i]
                }
                that.setData({
                    paihang: paihang
                })
            }
        })
        wx.request({
            url: app.data.baseUrl + '/api/Discover/cate_hot',
            data: {
                session_key: session_key,
                page: that.data.page
            },
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: function(res) {
                console.log('ressseee', res)
                that.setData({
                    cate_hot: res.data.data.list
                })
            }
        })

        wx.request({
            url: app.data.baseUrl + '/api/Discover/index',
            data: {
                session_key: session_key
            },
            method: 'POST',
            header: {
                "content-type": "application/x-www-form-urlencoded"
            },
            success: function(res) {
                console.log('0000', res)
                that.setData({
                    video: res.data.data.video,
                    cate: res.data.data.cate
                })
            }
        })

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    },
    // 跳转到搜索页面的函数
    bindfindDetail: function() {
        wx.navigateTo({
            url: 'findDetail/findDetail'
        })
    },
    bindrankingList: function() {
        wx.navigateTo({
            url: 'rankingList/rankingList'
        })
    },
    bingFind: function(e) {
        console.log(e)
        wx.navigateTo({
            url: 'find/find?id=' + e.currentTarget.id
        })
    },
    bingNext() {
        var that = this;
        var page = that.data.page;
        ++page;
        var session_key = wx.getStorageSync('session_key');
        wx.request({
            url: app.data.baseUrl + '/api/Discover/cate_hot',
            data: {
                session_key: session_key,
                page: page
            },
            method: 'POST',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },

            success: function(res) {
                console.log('resss', res)
                if (res.data.data.state == 1) {
                    page = 0
                }
                that.setData({
                    cate_hot: res.data.data.list,
                    page: page
                })
            }
        })
    },

})